<?php


namespace App\Traits;


use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

/**
 * Trait Helpers
 * @package App\Traits
 */
trait Helpers
{
    public function userInfo()
    {
        return Auth::guard('api')->user();
    }

    public function __get($name)
    {
        if ($name == 'user') return $this->userInfo();

        return null;
    }

    /**
     * db begin transaction
     */
    public function beginTransaction()
    {
        DB::beginTransaction();
    }

    /**
     * db commit
     */
    public function commit()
    {
        DB::commit();
    }

    /**
     * db rollback
     */
    public function rollback()
    {
        DB::rollBack();
    }

    public function transaction(\Closure $closure)
    {
        return DB::transaction($closure);
    }

    protected function createException($message = 'Service Exception', $code = 0)
    {
        return new \Exception($message, $code);
    }
}
